<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>随机背景色</title>
    <script type="text/javascript">
        let getColor = function () {
            let r = Math.floor(256 * Math.random());
            let g = Math.floor(256 * Math.random());
            let b = Math.floor(256 * Math.random());
            return "rgb(" + r + "," + g + "," + b + ")";
        }

        let changeBackgroundColor = function () {
            document.body.setAttribute("style", "background-color:" + getColor() + ";");
        }
    </script>
</head>
<body>
<script type="text/javascript">
    
    /* 循环 param1：函数，param2：时间 */
    setInterval(changeBackgroundColor, 500);
</script>
</body>
</html>